{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scientific Computing in Python with Numpy\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pre/Post-test\n", "This test is for testing your current skills in Python. You can use it in two ways:\n", "* pre-test: to test your skills beforehand. If you are already proficient in Python, and can do this test within approximately 15 minutes, you can scan through the notebook rather than carefully reading each sentence.\n", "* post-test: to test your skills after Notebook 4. Check whether you learned enough.\n", "\n", "**Calculating a derivative**\n", "Eric is asked to develop a tool for people that need to do some mathematical calculations. He is asked to write a function that calculates and plots the derivative of a given function. The derivative of a continuous function $f(x)$ can be approximated by $f'(x) = \\frac{f(x+\\epsilon)-f(x-\\epsilon)}{2\\epsilon}$ for some small value of $\\epsilon$. As Eric knows that the derivative of $f(x) = \\sin(x)$ is $f'(x) = \\cos(x)$, he uses this function to test whether his function works correct.\n", "- Make an array in the domain [0, 2*$\\pi$] with 1e4 even spaced values.\n", "- Plot the function $f(x)$ for this domain.\n", "- Write a function that calculates the derivative using the approach above.\n", "- Plot the graph of the derivative in the same figure.\n", "- Test the correctness of the function by using any other input function.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### Your Code" ] }, { "cell_type": "markdown", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-33372ef05bccfcb0", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## Learning objectives\n", "\n", "Numpy (Numerical Python) is a library designed for performing scientific computing in Python. \n", "\n", "In this notebook, we will introduce numpy arrays, a data structure introduced in numpy for working with vectors and matrices. We will explore how to create them, how to manipulate them, and how to use them for efficient numerical calculations using numpy functions. \n", "\n", "After completing this notebook, you are able to:\n", "* create (multidimensional) numpy arrays from a list of numbers\n", "* use indexing and slicing with (multidimensional) numpy arrays\n", "* iterate over a numpy array \n", "* perform mathematical operations on numpy arrays\n", "* use functions for creating arrays (eg. `np.zeros()`, `np.linspace()`, `np.random.random()`\n", "* use numpy functions for vectorized calculations\n", "* to demonstrate the speed increase of vectorized calculations using `time()`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "